<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<link rel="stylesheet" type="text/css" href="/static/component/laytp/module/cityPicker/city-picker.css">

<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span id="flowsetname"></span><div class="move_title"></div><?php include "../public/subturn.php";?></div></div>
    <div class="main-container">
        <div class="block-generic">
            <?php include "../public/substt.php";?>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>项目信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>项目名称</label>
                        <div class="layui-input-block">
                            <input type="hidden" id="business">
                            <input type="text" readonly name="enginid" class="layui-input enginid" onclick="openPage('../public/choose_engin.php?dom=enginid&page=piao_kai','80%','80%')">
                            <div class="choose_div" id="enginid" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_engin.php?dom=enginid&page=piao_kai','80%','80%')"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>



            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>本次申请开票</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>开票单号</label>
                        <div class="layui-input-block">
                            <input type="text" id="number" placeholder="请输入" disabled autocomplete="off" class="layui-input disabled">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>发票类型</label>
                        <div class="layui-input-block">
                            <select id="piaotype" name="piaotype" lay-filter="piaotype"></select>
                            <p class="error" id="piaotype_error" style="margin: 0;"></p>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>开票主题</label>
                        <div class="layui-input-block">
                            <input type="text" name="title" id="title" placeholder="请输入" clearable  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>本次开票金额含税(元)</label>
                        <div class="layui-input-block">
                            <input type="text" name="money" id="money" placeholder="请输入" clearable autocomplete="off" class="layui-input moneyinput">
                        </div>
                    </div>

                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>税率(%)</label>
                        <div class="layui-input-block">
                            <input type="number" name="rate" id="rate" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">税额(元)</label>
                        <div class="layui-input-block">
                            <input type="text" name="ratefee" id="ratefee" placeholder="自动计算：开票金额含税÷（1+税率/100）X税率/100" readonly autocomplete="off" class="layui-input moneyinput disabled">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>受票单位</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="shouer" class="layui-input shouer" onclick="openPage('../public/choose_dealcom.php?dom=shouer&page=piao_kai','80%','80%')">
                            <div class="choose_div" id="shouer" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_dealcom.php?dom=shouer&page=piao_kai','80%','80%')"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">统一社会信用代码</label>
                        <div class="layui-input-block">
                            <input type="text" name="ratenum" id="ratenum" placeholder="请输入" clearable  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">开户行</label>
                        <div class="layui-input-block">
                            <input type="text" name="unitbkname" id="unitbkname" placeholder="请输入" clearable  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">账号</label>
                        <div class="layui-input-block">
                            <input type="text" name="unitbknum" id="unitbknum" placeholder="请输入" clearable  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">地址</label>
                        <div class="layui-input-block">
                            <input type="text" name="unitaddr" id="unitaddr" placeholder="请输入" clearable  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">电话</label>
                        <div class="layui-input-block">
                            <input type="text" name="unittel" id="unittel" placeholder="请输入" clearable  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">施工地点</label>
                        <div class="layui-input-block">
                            <input type="text" name="shiaddr" id="shiaddr" placeholder="请输入" clearable  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>开票单位</label>
                        <div class="layui-input-block">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=kaier&type=dept&dept=chan&single=1','770px','490px');"></div>
                                <div class="tanxiannei" id="kaier" key="1"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=kaier&type=dept&dept=chan&single=1','770px','490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">备注</label>
                        <div class="layui-input-block">
                            <textarea id="explain" name="explain" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>



            <div class="buisness2 layui-hide">
                <div class="layui-form-item">
                    <div class="layui-row layui-col-space10">
                        <div class="edittits"><span>本次开票收取税费</span></div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-row layui-col-space10">
                        <div class="layui-col-md6">
                            <label class="layui-form-label"><text>*</text>本次开票应计税费(元)</label>
                            <div class="layui-input-block">
                                <input type="hidden" id="lian_shuirate">
                                <input type="text" name="yingshuifee" id="yingshuifee" placeholder="自动计算：本次开票金额含税*联营合同的税费费率/100" readonly autocomplete="off" class="layui-input moneyinput disabled">
                            </div>
                        </div>
                        <div class="layui-col-md6">
                            <label class="layui-form-label">税费收取说明</label>
                            <div class="layui-input-block">
                                <input type="text" name="shuishuo" id="shuishuo" placeholder="请输入" clearable  autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-row layui-col-space10">
                        <div class="layui-col-md6">
                            <label class="layui-form-label"><text>*</text>税费收取方式</label>
                            <div class="layui-input-block">
                                <select id="shuiqutype" name="shuiqutype" lay-filter="shuiqutype"></select>
                                <p class="error" id="shuiqutype_error" style="margin: 0;"></p>
                            </div>
                        </div>
                        <div class="layui-col-md6 shuiqutype3 layui-hide">
                            <label class="layui-form-label"><text>*</text>关联费用扣收</label>
                            <div class="layui-input-block">
                                <input type="text" readonly name="kouid" class="layui-input kouid" onclick="choose_detail_kou()">
                                <div class="choose_div" id="kouid" key="1"></div>
                                <span class="choose_one" onclick="choose_detail_kou()"><i class="layui-icon layui-icon-search"></i></span>
                            </div>
                        </div>
                    </div>
                </div>

            </div>


            <?php include '../public/flowqita.php'?>
            <?php include '../public/upinfo.php'?>
        </div>
    </div>
</form>

<?php include 'showrrboxtext.php'?>
<div><?php include '../public/shrrbox_addpage.php'?></div>
<script>
    var param_id = getQueryVariable('id') || 0;
    chu_flow_edit_yushen();

    $("#commentForm").validate({
        rules: {
            title: {required: true},
            money: {required: true},
            rate: {required: true},
            yingshuifee: {required: true},
        },
        messages:{
            title: {required: "请输入"},
            money: {required: "请输入"},
            rate: {required: "请输入"},
            yingshuifee: {required: "请输入"},
        }
    });



    function choose_detail_kou(){
        var enginid = get_choose_val('enginid');
        if(!enginid){
            facade.error("请先选择项目");return false;
        }
        openPage('../shou_xiang/choose_detail_kou.php?dom=kouid&page=piao_kai&status=1&enginid='+enginid,'80%','80%')
    }



    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_flowdata_edit_piao_kai, data:{id:param_id}}).done(function(res){
            if (res.code === 2000) {
                var data = res.data.data;
                chu_flow_qian(data);

                var engininfo = res.data.engininfo;
                if(engininfo){
                    set_choose_btn('enginid',engininfo.id,engininfo.name);
                    $("#business").val(engininfo.business);
                    $("#lian_shuirate").val(engininfo.lian_shuirate);
                    if(engininfo.business == 2){
                        $(".buisness2").removeClass('layui-hide');
                    }

                    set_right_relainfo(engininfo)
                }




                $("#number").val(data.number);
                $("#title").val(data.title);
                $("#money").val(data.money);
                $("#rate").val(data.rate);
                $("#ratefee").val(data.ratefee);
                $("#ratenum").val(data.ratenum);
                $("#unitbkname").val(data.unitbkname);
                $("#unitbknum").val(data.unitbknum);
                $("#unitaddr").val(data.unitaddr);
                $("#unittel").val(data.unittel);
                $("#shiaddr").val(data.shiaddr);
                $("#explain").val(data.explain);
                $("#yingshuifee").val(data.yingshuifee);
                $("#shuishuo").val(data.shuishuo);



                if(data.shuiqutype == 3){
                    $(".shuiqutype3").removeClass('layui-hide');
                    var kouidinfo = res.data.kouidinfo;
                    if(kouidinfo){
                        set_choose_btn('kouid',kouidinfo.id,kouidinfo.number+'（'+kouidinfo.money+'）');
                    }
                }


                if(data.shouer){
                    set_choose_btn('shouer',data.shouer,data.shouer);
                }


                if(data.kaier_info.length > 0){
                    tan_tags_init('#kaier', data.kaier_info);
                }

                xiala_zhan_one_zuo('piaotype',res.data.piaotype,data.piaotype)
                xiala_zhan_one_zuo('shuiqutype',res.data.shuiqutype,data.shuiqutype)


                initParseMoney();
                public_upload_file_load('upload_files', res.data.files);
                render_from();
            }
        });

        form.on('select(piaotype)', function(data){
            if(data.value == ''){
                $('#piaotype_error').show().text('请选择');
                $('#piaotype_error').parent().find('input').addClass('select_error');
            }else{
                $('#piaotype_error').hide();
                $('#piaotype_error').parent().find('input').removeClass('select_error');
            }
        });

        form.on('select(shuiqutype)', function(data){
            if(data.value == 3){
                $(".shuiqutype3").removeClass('layui-hide');
            }else{
                $(".shuiqutype3").addClass('layui-hide');
            }

            if(data.value == ''){
                $('#shuiqutype_error').show().text('请选择');
                $('#shuiqutype_error').parent().find('input').addClass('select_error');
            }else{
                $('#shuiqutype_error').hide();
                $('#shuiqutype_error').parent().find('input').removeClass('select_error');
            }
        });

        form.on('submit(add)', function(data){
            data.field.isturn = $(this).attr('key') || 0;
            data.field.isshen = $(this).attr('isshen') || 0;
            data.field.flowrelas = get_choose_val('flowrelas');
            data.field.advaners = tan_tags_getvalue("#advaners", 'user');
            data.field.nexter = tan_tags_getvalue("#nexter", 'user');



            data.field.enginid = get_choose_val('enginid');
            data.field.shouer = get_choose_val('shouer');
            data.field.kaier = tan_tags_getvalue("#kaier", 'dept');
            data.field.kouid = get_choose_val('kouid');

            if(data.field.isturn > 0){
                var validRes = $("#commentForm").valid();

                formValid('enginid');
                if(data.field.enginid == undefined || !data.field.enginid){
                    validRes = false;
                }


                if(data.field.piaotype == ''){
                    $('#piaotype_error').show().text('请选择');
                    $('#piaotype_error').parent().find('input').addClass('select_error');
                    validRes = false;
                }else{
                    $('#piaotype_error').hide();
                    $('#piaotype_error').parent().find('input').removeClass('select_error');
                }


                formValid('shouer');
                if(data.field.shouer == undefined || !data.field.shouer){
                    validRes = false;
                }

                if(!data.field.kaier){
                    $("#kaier").parents('.tanxian').addClass('tanerror');
                    $('#kaier_tanerror').text('请选择');
                    validRes = false;
                }else{
                    $("#kaier").parents('.tanxian').removeClass('tanerror');
                    $('#kaier_tanerror').text('');
                }

                var business = $("#business").val();
                if(business == 2){
                    if(data.field.shuiqutype == ''){
                        $('#shuiqutype_error').show().text('请选择');
                        $('#shuiqutype_error').parent().find('input').addClass('select_error');
                        validRes = false;
                    }else{
                        $('#shuiqutype_error').hide();
                        $('#shuiqutype_error').parent().find('input').removeClass('select_error');
                    }


                    if(data.field.shuiqutype == 3){
                        formValid('kouid');
                        if(data.field.kouid == undefined || !data.field.kouid){
                            validRes = false;
                        }

                    }
                }



                if(!validRes){return false;}
            }



            data.field.id = param_id;
            data.field.files = public_upload_file_value('upload_files');
            data = parseMoney(data);

            public_flow_submit(data.field, ask_flowdata_add_piao_kai, ask_flowdata_edit_piao_kai, $(this).attr('but'));
            return false;
        });

    });


    $("#money, #rate").on('input propertychange',function () {
        var money = parseValidNum($("#money").val());
        var rate = parseValidNum($("#rate").val());

        var ratefee = money/(1+rate/100) * rate/100;
        $("#ratefee").val(parseFormatNum(ratefee,2));

        var lian_shuirate = parseValidNum($("#lian_shuirate").val());
        var yingshuifee = money*lian_shuirate/100;
        $("#yingshuifee").val(parseFormatNum(yingshuifee,2));
    });

</script>
</body>
</html>
